package com.rongc.client.freight.wxapi;


import android.content.Intent;
import android.widget.ImageView;
import android.widget.TextView;

import com.rongc.client.core.Constants;
import com.rongc.client.core.utils.LogUtils;
import com.rongc.client.freight.R;
import com.rongc.client.freight.base.BaseActivity;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import butterknife.Bind;

public class WXPayEntryActivity extends BaseActivity implements IWXAPIEventHandler {
	@Bind(R.id.tv_result)
	TextView mTvRlt;
	@Bind(R.id.iv_result)
	ImageView mIvRlt;
	private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
	
    private IWXAPI api;
	
	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {
		LogUtils.d("onPayFinish, errCode = " + resp.errCode);
		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
			if(resp.errCode == 0){
				mTvRlt.setText(getString(R.string.pay_result_callback_msg, getString(R.string.normal_succ)));
				mIvRlt.setImageResource(R.mipmap.pay_succ);
			}else {
				mTvRlt.setText(getString(R.string.pay_result_callback_msg, getString(R.string.normal_fail)));
				mIvRlt.setImageResource(R.mipmap.pay_fail);
			}
			/*AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setTitle("提示");
			builder.setMessage(getString(R.string.pay_result_callback_msg, String.valueOf(resp.errCode)));
			builder.show();*/
		}
	}

	@Override
	public void initView() {
		initToolbar("支付结果");
		api = WXAPIFactory.createWXAPI(this, Constants.WXAPP_ID);
		api.handleIntent(getIntent(), this);
	}

	@Override
	public int getLayoutId() {
		return R.layout.pay_result;
	}
}